package cn.gwm.flink.streaming.dwm.charge.bean;

import cn.gwm.flink.streaming.dwm.charge.model.ChargeConstant;
import cn.gwm.flink.streaming.dwm.charge.model.ChargeStateEnum;
import cn.hutool.json.JSONObject;
import lombok.Data;
import lombok.experimental.Accessors;
import org.apache.flink.api.common.state.ListState;
import org.apache.flink.api.common.state.MapState;
import org.apache.flink.api.common.state.ValueState;
import org.apache.flink.util.Collector;

import javax.validation.constraints.NotNull;
import java.io.Serializable;

/**
 * @Author: liangguang
 * @Date: 2022/11/11
 * @Description: 充电参数类，属性都是 稳态处理需要的字段
 */
@Data
@Accessors(chain = true)
public class ChargeArgs implements Serializable {
    /**
     * 数据常量字段
     */
    private ChargeConstant constant;

    /**
     * 当前条数据
     */
    private JSONObject realNowData;

    /**
     * 当前状态的首条数据
     */
    private JSONObject firstData;
    /**
     * 上一个状态的结束数据
     */
    private JSONObject prevEndData;
    /**
     * 当前状态的上一条数据
     */
    private JSONObject prevData;
    /**
     * 一级汇总
     */
    private ValueState<JSONObject> summarState;
    /**
     * 二级汇总
     */
    private ValueState<JSONObject> bandSummarState;
    /**
     * 缓存数据
     */
    private ListState<JSONObject> listState;
    /**
     * 首次开始中断时间
     */
    private ValueState<Long> chargeBreakState;
    /**
     * 物理插枪时间
     */
    private ValueState<Long> ConnectTimeState;
    /**
     * 当前数据的状态
     */
    @NotNull(message = "当前状态不能为空")
    private ChargeStateEnum nowState;
    /**
     * 有效充电时间
     */
    private ValueState<Long> effectiveChargeTime;

    /**
     * 充电过程中优惠信息的存储
     */
    private MapState<Long, ChargeFavourable> favourableMapState;
    /**
     * 充电模式首条 电量
     */
    private MapState<String, JSONObject> chargeModelFirstState;

    /**
     * 收集器，用于将数据发送给下游
     */
    private Collector<JSONObject> out;

    /**
     * phoenix 视图名
     */
    private String phoenixTableName;

    /**
     * phoenix 视图 库
     */
    private String dataBase;

    private Boolean tripRedis;
    /**
     * 生成 summar时使用 默认完整 1
     */
    private Integer isComplete = 1;

    public void clear() {
        effectiveChargeTime.clear();
        ConnectTimeState.clear();
        chargeBreakState.clear();
        listState.clear();
        bandSummarState.clear();
        summarState.clear();
        favourableMapState.clear();
    }
}
